package cn.sciento.farm.devicemanager.gateway.model.downlink;

import cn.sciento.farm.devicemanager.common.constant.MqttConstant;
import com.alibaba.fastjson.JSON;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.HashMap;
import java.util.Map;

@Data
@EqualsAndHashCode(callSuper = false)
public class SciGwBlockConfigData extends AbstractBlockData {


    private String concentrator;

    private Integer baud = 9600;

    private Integer period;

    private Integer recovery;

    private Integer refresh;

    private Integer param;



    @Override
    public String generateId() {
        return String.format(MqttConstant.SCI_CONFIG_BLOCK_ID, concentrator);
    }


    @Override
    public String generateStatus() {
        return null;
    }

    @Override
    public MqttContent generate() {
        String topic = String.format(MqttConstant.SCI_GW_CONFIG_TOPIC, concentrator);
        Map<String,Object> map = new HashMap<>();
        map.put("baud",baud);
        map.put("period",period);
        map.put("recovery",recovery);
        map.put("refresh",refresh);
        map.put("param",param);
        String payload = JSON.toJSONString(map);
        MqttContent mqttContent = new MqttContent(topic,payload);
        return mqttContent ;
    }
}
